↜ Back to index Introduction to Numerical Analysis 1
Solution Lecture a3
Exercise 1
! Implementation of the Euler method for y' = f(t, y)
implicit none
integer i, n
real y, h, t, f
= 10
n = 1. / n ! note 1. and not 1
h
! Initial data
= 1.
y print *, 0., y
do i = 1, n
! One step of the Euler method.
= (i - 1) * h
t ! f(t, y)
= y
f = y + h * f
y print *, i * h, y
enddo
end
Exercise 2
! Implementation of the Euler method for y' = f(t, y)
implicit none
integer i, n
real y, h, t, f
= 45
n = 1. / n ! note 1. and not 1
h
! Initial data
= 1.
y print *, 0., y
do i = 1, n
! One step of the Euler method.
= (i - 1) * h
t ! f(t, y)
= -100 * y
f = y + h * f
y print *, i * h, y
enddo
end
Exercise 3
! Implementation of the Euler method for y' = f(t, y)
implicit none
integer i, n
real y, h, t, f
= 20
n ! interval (0, 5)
= 5. / n
h
! Initial data
= 1.
y print *, 0., y
do i = 1, n
! One step of the Euler method.
= (i - 1) * h
t ! f(t, y)
= y * sin(t)
f = y + h * f
y print *, i * h, y
enddo
end